package com.mo.lib.ui.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.*
import com.dylanc.longan.topActivity
import com.mo.lib.R
import com.mo.lib.utils.isOutOfBounds

/**
 * @ author：mo
 * @ data：2022/4/27:13:30
 * @ 功能：
 */
  class KBaseDialog(style: Int = R.style.BaseDialogStyle) : Dialog(topActivity, style) {
    /** 视图外点击标识*/
     var outCanAble = false
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//        setOnKeyListener { _, keyCode, event ->
//            if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_UP) {  //返回键监听
//                dismiss()
//            }
//            false
//        }
    }


    /** 触摸dialog外部关闭dialog*/
    override fun onTouchEvent(event: MotionEvent): Boolean {
        if (outCanAble&&window!!.decorView.isOutOfBounds( event)) {
            cancel()
            dismiss()
        }
        return super.onTouchEvent(event)
    }
}
